package cn.hnucm.searchesservice.dao;


import org.elasticsearch.action.index.IndexRequest;
import org.elasticsearch.action.index.IndexResponse;
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.RestHighLevelClient;
import org.elasticsearch.common.xcontent.XContentType;

import java.io.IOException;

/**
 * @Description:
 * @author: chenjintao
 * @Date: 2021/12/23 1:02
 */
public interface Dao {

    /**
     * 将整个类型添加到数据库中并放回结果
     * @param request
     * @param s
     * @param client
     * @return
     */
    static Boolean getaCreateResult(IndexRequest request, String s, RestHighLevelClient client) {
        request.timeout("1s");
        request.source(s, XContentType.JSON);
        IndexResponse indexResponse = null;
        try {
            indexResponse = client.index(request, RequestOptions.DEFAULT);
            return indexResponse.getResult().toString().equalsIgnoreCase("CREATED");
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }
}
